/**
 * 
 */
package com.jie.eclipse.pan.swtitem.actiongroup;

import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.actions.ActionGroup;

import com.jie.eclipse.pan.data.BaseDataEntity;
import com.jie.eclipse.pan.editors.utils.PanImageHelper;
import com.jie.eclipse.pan.gef.dialog.BaseDialog;
import com.jie.eclipse.pan.popup.wizardpage.BasePage;
import com.jie.eclipse.pan.swtitem.widgets.BaseComposite;
import com.jie.eclipse.pan.utils.handle.FileHandle;

/**
 * @author yanjie
 *
 */
public class BaseActionGroup extends ActionGroup{
	private BaseComposite bc = null;
	private FileHandle fileHandle = null;
	
	private String key = "";
	private String action = "";
	private Object obj = null;
	BaseDataEntity data = null;
	

	public BaseActionGroup(Object obj) {
		this.obj = obj;
	}
	
	public BaseActionGroup(Object obj,String key,String action) {
		this.key = key;
		this.obj = obj;
		this.action = action;
	}
	/**
	 * 
	 */
	public BaseActionGroup(BaseComposite bc,FileHandle fileHandle) {
		this.bc = bc;
		this.fileHandle = fileHandle;
	}
	
	public ImageDescriptor getImageDesc(String fileName){
		try{
			return PanImageHelper.getInstance().getImageDescriptor("icons/"+fileName);
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}
	
	public ActionContributionItem createActionContributionItem(IAction action){
		ActionContributionItem aci = new ActionContributionItem(action);
		aci.setMode(ActionContributionItem.MODE_FORCE_TEXT);
		return aci;
	}
	
	public BaseComposite getBaseComposite() {
		return bc;
	}
	
	public FileHandle getFileHandle() {
		return fileHandle;
	}
	
	public String getAction() {
		return action;
	}
	public String getKey() {
		return key;
	}
	public Object getObj() {
		return obj;
	}
	
	public boolean isBaseDialog(){
		if(this.obj != null && this.obj instanceof BaseDialog){
			return true;
		}else{
			return false;
		}
	}
	
	public boolean isBasePage(){
		if(this.obj != null && this.obj instanceof BasePage){
			return true;
		}else{
			return false;
		}
	}
	
	public BaseDialog getBaseDialog(){
		return (BaseDialog)this.obj;
	}
	
	public BasePage getBasePage(){
		return (BasePage)this.obj;
	}
	
	public BaseDataEntity getData(){
		if(isBaseDialog()){
			data = getBaseDialog().getDataInstance();
		}else if(isBasePage()){
			data = getBasePage() .getDataInstance();
		}else{
			data = new BaseDataEntity();
		}
		return data;
	} 
	 
}
